﻿using UnityEngine;
using System.Collections;
using BehaviorDesigner.Runtime;

public enum FactionType
{
    Left,
    Right,
    Null,
};

public class BattleManager : MonoBehaviour
{
    static public BattleManager Instance;

    private void Awake()
    {
        Instance = this;
    }

    // Use this for initialization
    void Start ()
    {
        //  所有人
        InitTarget();

        //  二个阵营

        //  
        SetBuffer();
    }
	
	// Update is called once per frame
	void Update ()
    {
	
	}

    [SerializeField]
    public Targetable[] targets;

    void InitTarget()
    {
        if (targets == null ||
            targets.Length <= 0)
            return;

        targets[0]._skillData = ReadSkillData("4");
        targets[0]._bRoleData = ReadRoleData("2");

        targets[1]._skillData = ReadSkillData("6");
        targets[1]._bRoleData = ReadRoleData("3");

        targets[2]._skillData = ReadSkillData("3");
        targets[2]._bRoleData = ReadRoleData("1");

    }

    bSkillData ReadSkillData(string i)
    {
        string file = ZoneConfig.BattleCsvPath + i + "_skill.txt";

        string content = System.IO.File.ReadAllText(file);

        bSkillData data = JsonUtility.FromJson<bSkillData>(content);

        return data;
    }

    bRoleData ReadRoleData(string i)
    {
        string file = ZoneConfig.RoleCsvPath + i + "_role.txt";

        string content = System.IO.File.ReadAllText(file);

        bRoleData data = JsonUtility.FromJson<bRoleData>(content);

        return data;
    }

    #region Buff
    public BehaviorTree _BehaviorTree;
    public btBufferShared _btBufferShared;

    void SetBuffer()
    {
        btBufferCfg cfg = ReadBuffData("3");

        _btBufferShared.Serialize(cfg);
        _BehaviorTree.EnableBehavior();
    }

    btBufferCfg ReadBuffData(string i)
    {
        string file = ZoneConfig.BuffCsvPath + i + "_buffer.txt";

        string content = System.IO.File.ReadAllText(file);

        btBufferCfg data = JsonUtility.FromJson<btBufferCfg>(content);

        return data;
    }
    #endregion
}
